package com.example.blog.controller;

import com.example.blog.common.pojo.request.AddBlogParam;
import com.example.blog.common.pojo.request.UpBlogParam;
import com.example.blog.common.pojo.response.BlogInfoResponse;
import com.example.blog.service.BlogService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Li_yizYa
 * Date: 2025/7/25
 * Time: 19:08
 */
@Slf4j
@RestController
@RequestMapping("/blog")
public class BlogController {

    @Resource(name = "blogServiceImpl")
    private BlogService blogService;

    @GetMapping("/getList")
    public List<BlogInfoResponse> getList() {
        log.info("获取博客列表");
        return blogService.getList();
    }

    @GetMapping("/getBlogDetail")
    public BlogInfoResponse getBlogDetail(@NotNull Integer blogId) {
        log.info("获取博客详情, blogId: {}", blogId);
        return blogService.getBlogDetail(blogId);
    }

    @PostMapping("/add")
    public Boolean addBlog(@Validated @RequestBody AddBlogParam param) {
        log.info("添加博客，标题:{}", param.getTitle());
        return blogService.addBlog(param);
    }

    @PostMapping("/update")
    public Boolean updateBlog(@Validated @RequestBody UpBlogParam param) {
        log.info("更新博客, 博客ID: {}", param.getId());
        return blogService.updateBlog(param);
    }

    @PostMapping("/delete")
    public Boolean deleteBlog(@NotNull Integer blogId) {
        log.info("删除博客, 博客ID: {}", blogId);
        return blogService.deleteBlog(blogId);
    }
}
